module("Parse a document with a single root element and check its name");

test("Simple name with element closing in the same segment", function() {
  var parser = new XmlParser();
  var doc = parser.parse("<root/>");
  equal("root", doc.rootElement.name);
});

test("Simple name with element closing in another segment", function() {
  var parser = new XmlParser();
  var doc = parser.parse("<root></root>");
  equal("root", doc.rootElement.name);
});

test("Name with underscore element closing in another segment", function() {
  var parser = new XmlParser();
  var doc = parser.parse("<root_elem></root_elem>");
  equal("root_elem", doc.rootElement.name);
});

test("Name with hyphen element closing in another segment", function() {
  var parser = new XmlParser();
  var doc = parser.parse("<root-elem></root-elem>");
  equal("root-elem", doc.rootElement.name);
});

module("Parse a document with a child elements and check their names");

test("Root with single child", function() {
  var parser = new XmlParser();
  var doc = parser.parse(
    "<first>" +
      "<second>" +
        "<third/>" +
      "</second>" +
    "</first>");
  equal("first", doc.rootElement.name);
  equal("second", doc.rootElement["second"].name);
  equal("third", doc.rootElement["second"]["third"].name);
});

module("Parse a document with a header");

test("Header before root", function() {
  var parser = new XmlParser();
  var doc = parser.parse(
    "<?xml version=\"1.0\"?>" +
    "<first>" +
    "</first>");
  equal("first", doc.rootElement.name);
});

module("Complex XML parse");

test("Parse Google weather API response", function() {
  var xmlstring = "<?xml version='1.0'?><xml_api_reply version='1'><weather module_id='0' tab_id='0' mobile_row='0' mobile_zipped='1' row='0' section='0' ><forecast_information><city data='haifa,israel'/><postal_code data='haifa,israel'/><latitude_e6 data=''/><longitude_e6 data=''/><forecast_date data='2012-03-27'/><current_date_time data='1970-01-01 00:00:00 +0000'/><unit_system data='US'/></forecast_information><current_conditions><condition data='Cloudy'/><temp_f data='55'/><temp_c data='13'/><humidity data='Humidity: 82%'/><icon data='/ig/images/weather/cloudy.gif'/><wind_condition data='Wind: SE at 5 mph'/></current_conditions><forecast_conditions><day_of_week data='Tue'/><low data='55'/><high data='64'/><icon data='/ig/images/weather/chance_of_rain.gif'/><condition data='Chance of Rain'/></forecast_conditions><forecast_conditions><day_of_week data='Wed'/><low data='52'/><high data='63'/><icon data='/ig/images/weather/chance_of_rain.gif'/><condition data='Chance of Rain'/></forecast_conditions><forecast_conditions><day_of_week data='Thu'/><low data='52'/><high data='63'/><icon data='/ig/images/weather/chance_of_storm.gif'/><condition data='Chance of Storm'/></forecast_conditions><forecast_conditions><day_of_week data='Fri'/><low data='54'/><high data='63'/><icon data='/ig/images/weather/chance_of_rain.gif'/><condition data='Chance of Rain'/></forecast_conditions></weather></xml_api_reply>".replace(/'/g, "\"");
  
  var parser = new XmlParser();
  var doc = parser.parse(xmlstring);
  equal("xml_api_reply", doc.rootElement.name);
});